import React, { Component } from 'react';
import { connect } from 'dva';
import { Modal, Form, Input, InputNumber,Table, Popconfirm } from 'antd';
const FormItem = Form.Item;
var _this,_props,_state;

class GroupContentModal extends Component {
  constructor(props) {
    super(props);
    this.state = {

    };
  }

  deleteHandler(id){
     _props.dispatch({
      type: _props.removeAttr,
      payload: {id:id,groupId:_props.assetGroupId,assetTypeId:_props.assetTypeId} ,
    });
  }

  onEditItem(id){
     _props.dispatch({
      type: _props.qryAttrById,
      payload: id ,
    });
  }

  render() {
   const { contentList} = this.props.contentList;
   const { dispatch} = this.props.dispatch;
    _this = this;
    _state = this.state;
    _props = this.props;

   const columns = [{
    title: '属性名称',
    dataIndex: 'lable',
    key: 'lable',
    width: 100,
  },{
    title: '字段',
    dataIndex: 'field',
    key: 'field',
    width: 120,
  },{
    title: '默认值',
    dataIndex: 'defValue',
    key: 'defValue',
    width: 100,
  },{
    title: '类型',
    dataIndex: 'type',
    key: 'type',
    width: 80,
    render: (text, record) => {
      if (record.type == 1) {
        return '文本';
      };
      if (record.type == 2) {
        return '数值';
      };
      if (record.type == 3) {
        return '多行文本';
      };
      if (record.type == 4) {
        return '下拉';
      };
    },
  },{
    title: '选项',
    dataIndex: 'options',
    key: 'options',
    width: 120,
  },{
    title: '长度',
    dataIndex: 'size',
    key: 'size',
    width: 60,
  },{
    title: '是否显示',
    dataIndex: 'isDisplay',
    key: 'isDisplay',
    width: 80,
    render: (text, record) => {
      if (record.isDisplay == 1) {
        return '显示';
      };
      if (record.isDisplay ==0) {
        return '不显示';
      };
    },
  },{
    title: '是否必填',
    dataIndex: 'isNotNull',
    key: 'isNotNull',
    width: 80,
    render: (text, record) => {
      if (record.isNotNull == 1) {
        return '必填';
      };
      if (record.isNotNull ==0) {
        return '不必填';
      };
    },
  }
  // , {
  //   title: '备注',
  //   dataIndex: 'intro',
  //   key: 'intro',
  //   width: 100,
  // }
  ,{
    title: '操作',
    key: 'operation',
    width: 100,
    render: (text, record) => (
        <span>
           <a onClick={this.onEditItem.bind(null, record.id_)}>编辑</a>
            <span className="ant-divider" />
            <Popconfirm title="确认删除？" onConfirm={this.deleteHandler.bind(null, record.id_)}>
            <a>删除</a>
            </Popconfirm>
        </span>
    ),
  }];
  
    return (
       <div style={{backgroundColor:'#fff'}}>
        <div style={{}}>
          <div style={{width:'100%',padding:'20px',}}>
            <Table columns={columns}
                 rowKey={record => record.id_}
                 dataSource={this.props.contentList}
                 pagination={false}
          />
          </div>
        </div>
    </div>
    );
  }
}

export default Form.create()(GroupContentModal);
